package com.czl.module_storehouse.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czl.base.data.bean.tengyun.LocatListBean;
import com.czl.module_storehouse.R;

import java.util.HashSet;
import java.util.List;

/**
 * @author xubin
 */
public class SaveStorageLocAdapter extends BaseNumAdapter<LocatListBean> {

    private int sortBeanType;
    private final HashSet<Integer> mSelectedSet;

    public SaveStorageLocAdapter(int layoutResId, @Nullable List<LocatListBean> data, HashSet<Integer> mSelectedSet) {
        super(layoutResId, data);
        this.mSelectedSet = mSelectedSet;
    }

    public int getSortBeanType() {
        return sortBeanType;
    }

    public void setSortBeanType(int sortBeanType) {
        this.sortBeanType = sortBeanType;
    }

    @Override
    public int getMaxCount(LocatListBean item) {
        return maxCount - item.getStockNum(getData());
    }

    @Override
    public int getMinCount(LocatListBean item) {
        return 0;
    }

    @Override
    protected void setAfterTextChanged(BaseViewHolder helper, LocatListBean bean, int count) {
        if (bean != null) {
            bean.setStorageNum(count);
            bean.setStockNum(count);
            bean.setShiftNum(count);
            bean.setAddNum(count);
            bean.setShiftLocatOut(String.valueOf(bean.getStorehouseLocatId()));
        }
    }

    private int totalMaxStockNum(LocatListBean item) {
        return maxCount - item.getStockNum(getData());
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, LocatListBean item) {
        item.setCount(item.getAddNumByType());
        super.convert(helper, item);
        helper.setText(R.id.tv_loc, "库位：" + item.getStorehouseLocatName());
        helper.itemView.setOnLongClickListener(v -> {
            remove(item);
            mSelectedSet.remove(item.getStorehouseLocatId());
            return false;
        });
    }
}
